//
//  SingleNewsCell.m
//  SouthChina
//
//  Created by creator_lq on 14/12/24.
//  Copyright (c) 2014年 科创. All rights reserved.
//

#import "SingleNewsCell.h"


@implementation SingleNewsCell


@synthesize message;
@synthesize publicId;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        _titleLabel =[[UILabel alloc]initWithFrame:CGRectZero];
        _timeLabel =[[UILabel alloc]initWithFrame:CGRectZero];
        _myIamgeView =[[UIImageView alloc]initWithFrame:CGRectZero];
        _contentLable =[[UILabel alloc]initWithFrame:CGRectZero];
        _lookLabel =[[UILabel alloc]initWithFrame:CGRectZero];
        
        _allcontentView =[[UIView alloc]initWithFrame:CGRectZero];

        [_titleLabel setFont: [UIFont fontWithName:@"TrebuchetMS-Bold" size:15]];
        [_titleLabel setBackgroundColor:[UIColor clearColor]];
        
        _timeLabel.textColor = [UIColor lightGrayColor];
        [_timeLabel setBackgroundColor:[UIColor clearColor]];
        [_timeLabel setFont:[UIFont systemFontOfSize:12]];
        
        
        [_contentLable setFont:[UIFont systemFontOfSize:13]];
        [_lookLabel setFont:[UIFont fontWithName:@"TrebuchetMS-Bold" size:14]];
        
        _backgroundImage =[[UIImageView alloc]initWithFrame:CGRectZero];

        [self addSubview:_backgroundImage];

        [self addSubview:_allcontentView];

        
        [_backgroundImage addSubview:_titleLabel];
        [_backgroundImage addSubview:_timeLabel];
        [_backgroundImage addSubview:_myIamgeView];
        [_backgroundImage addSubview:_contentLable];
        [_backgroundImage addSubview:_lookLabel];

        
        [self setBackgroundColor:[UIColor clearColor]];
        
   

    }
    return self;
}


- (void)layoutSubviews{
    
    [super layoutSubviews];
    NSDictionary * allmap =[message getValue:@"news"];
    NSArray * artlist = [allmap objectForKey:@"Articles"];
    NSDictionary *fistMap = [artlist objectAtIndex:0];
    
    self.allcontentView.frame =  CGRectMake(0, 0, SCREEN_WIDTH, SINGLE_NEWS_CELL);
    self.backgroundImage.frame =  CGRectMake(NEW_CELL_COM_GAP, NEW_CELL_COM_GAP, SCREEN_WIDTH-2*NEW_CELL_COM_GAP, SINGLE_NEWS_CELL-2*NEW_CELL_COM_GAP);
    [self.backgroundImage setImage:[[UIImage imageNamed:@"news_background_normal"]stretchableImageWithLeftCapWidth:5 topCapHeight:5]];

    self.titleLabel.frame = CGRectMake(NEW_CELL_COM_GAP, NEW_CELL_COM_GAP, SCREEN_WIDTH-4*NEW_CELL_COM_GAP, TITLE_HEIGHT);
    self.timeLabel.frame = CGRectMake(NEW_CELL_COM_GAP,2*NEW_CELL_COM_GAP+TITLE_HEIGHT,  SCREEN_WIDTH-4*NEW_CELL_COM_GAP, TIME_HEIGHT);
    self.myIamgeView.frame = CGRectMake(NEW_CELL_COM_GAP,3*NEW_CELL_COM_GAP+TITLE_HEIGHT+TIME_HEIGHT,  SCREEN_WIDTH-4*NEW_CELL_COM_GAP, IMAGE_HEIGHT);
    self.contentLable.frame = CGRectMake(NEW_CELL_COM_GAP,4*NEW_CELL_COM_GAP+TITLE_HEIGHT+TIME_HEIGHT+IMAGE_HEIGHT,  SCREEN_WIDTH-4*NEW_CELL_COM_GAP, CONTENT_HEIGHT);
    self.lookLabel.frame = CGRectMake(NEW_CELL_COM_GAP,5*NEW_CELL_COM_GAP+TITLE_HEIGHT+TIME_HEIGHT+IMAGE_HEIGHT+CONTENT_HEIGHT,  SCREEN_WIDTH-4*NEW_CELL_COM_GAP, LOOK_HEIGHT);
    
    self.titleLabel.text = [fistMap objectForKey:@"Title"];
    self.timeLabel.text = [message.upate_time stringFromDate];
    NSString * url =[fistMap objectForKey:@"PicUrl"];
    NSURL *urll = [NSURL URLWithString: [url hasPrefix:@"http"]?url:[NSString stringWithFormat:@"%@%@",DE.fileEngineeUrl,url]];
    [self.myIamgeView setImageWithURL:urll  placeholderImage:[UIImage imageNamed:@"empty_photo"]];

    self.contentLable.text = [fistMap objectForKey:@"Description"];
    self.contentLable.numberOfLines=2;
    self.lookLabel.text = @"查看全文";
    
    
    
    

}

-(void) setMsgCellValue:(Message*)msg publicId:(NSString*)publicIdd{

    self.message = msg;
    self.publicId = publicIdd;

}

@end
